<script setup>
import AppHeader from '@/components/AppHeader.vue';
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();
console.log(route);


// 缓存的路由组件名称列表
const cachedRoutes = ref(['home']);

// 添加禁止双击放大的meta标签
onMounted(() => {
  // 添加禁止双击放大的meta标签
  const metaViewport = document.querySelector('meta[name="viewport"]');
  if (metaViewport) {
    metaViewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');
  } else {
    const meta = document.createElement('meta');
    meta.name = 'viewport';
    meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
    document.head.appendChild(meta);
  }
  
  // // 预加载可能会访问的路由组件
  // setTimeout(() => {
  //   const preloadRoutes = ['tireCalculator', 'signIn', 'controllerCategories'];
  //   preloadRoutes.forEach(route => {
  //     const link = document.createElement('link');
  //     link.rel = 'prefetch';
  //     link.as = 'script';
  //     link.href = `/assets/js/${route}.js`;
  //     document.head.appendChild(link);
  //   });
  // }, 2000);
});
</script>

<template>
  <div id="app" v-if="!route.meta.showHeader">
    <AppHeader />
  {{ route.meta.showHeader }}
    <div class="app-content">
      <router-view v-slot="{ Component, route }">
        <transition name="fade" mode="out-in">
          <keep-alive :include="cachedRoutes">
            <component :is="Component" :key="route.path" />
          </keep-alive>
        </transition>
      </router-view>
    </div>
    
    <!-- 背景动画元素 -->
    <div class="app-background">
      <div class="grid-overlay"></div>
      <div class="glow-effect"></div>
    </div>
  </div>
  <router-view v-else />
</template>

<style>
:root {
  --primary-color: #ff3a3a;
  --primary-hover: #e62e2e;
  --primary-light: rgba(255, 58, 58, 0.2);
  --bg-dark: #0f1923;
  --bg-darker: rgba(7, 15, 25, 0.75);
  --text-color: #f0f9ff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --secondary-color: #333;
  --border-radius: 0;
  --box-shadow: 0 4px 8px rgba(255, 0, 0, 0.2);
}

html, body {
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-family: 'Microsoft YaHei', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--bg-dark);
  color: var(--text-color);
  line-height: 1.5;
  overflow-x: hidden;
  scroll-behavior: smooth;
  height: 100%;
}

* {
  box-sizing: border-box;
}

#app {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  line-height: 1.2;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--primary-hover);
}

button, input, select, textarea {
  font-family: inherit;
}

.app-content {
  /* padding-top: 70px; */
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  z-index: 1;
  will-change: transform;
  height: calc(100% - 60px);
  /* overflow: auto; */
}


/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.fade-enter-from {
  opacity: 0;
  transform: translateY(10px);
}

.fade-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}

/* 背景动画样式 */
.app-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    linear-gradient(90deg, rgba(255, 58, 58, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(255, 58, 58, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.15;
}

.glow-effect {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 800px;
  height: 800px;
  background: radial-gradient(circle, rgba(255, 58, 58, 0.08), transparent 70%);
  transform: translate(-50%, -50%);
  opacity: 0.5;
  animation: appGlow 15s infinite alternate ease-in-out;
}

@keyframes appGlow {
  0% {
    opacity: 0.3;
    transform: translate(-50%, -50%) scale(0.8);
  }
  50% {
    opacity: 0.5;
    transform: translate(-60%, -40%) scale(1);
  }
  100% {
    opacity: 0.4;
    transform: translate(-40%, -60%) scale(0.9);
  }
}

/* 装饰元素 */
/* .corner-decoration {
  position: fixed;
  width: 50px;
  height: 50px;
  pointer-events: none;
  z-index: 90;
}

.top-left {
  top: 0;
  left: 0;
  border-top: 2px solid rgba(255, 58, 58, 0.5);
  border-left: 2px solid rgba(255, 58, 58, 0.5);
}

.top-right {
  top: 0;
  right: 0;
  border-top: 2px solid rgba(255, 58, 58, 0.5);
  border-right: 2px solid rgba(255, 58, 58, 0.5);
}

.bottom-left {
  bottom: 0;
  left: 0;
  border-bottom: 2px solid rgba(255, 58, 58, 0.5);
  border-left: 2px solid rgba(255, 58, 58, 0.5);
}

.bottom-right {
  bottom: 0;
  right: 0;
  border-bottom: 2px solid rgba(255, 58, 58, 0.5);
  border-right: 2px solid rgba(255, 58, 58, 0.5);
} */

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-hover);
}

/* 文本选择样式 */
::selection {
  background-color: var(--primary-light);
  color: white;
}
</style>